/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package finance.creditControl.sessionbean;

import finance.util.exception.CreditAccountFrozenException;
import finance.util.exception.CreditLimitExceededException;
import finance.util.exception.FinanceException;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import sales.entity.SalesOrderEntity;

/**
 *
 * @author ReinForceII
 */
@Stateless
@LocalBean
public class CreditControlSessionBean {

    @PersistenceContext
    private EntityManager em;
    
    public void creditCheck (SalesOrderEntity salesOrder) throws FinanceException{
        
        if (salesOrder.getCustomer().getName().equals("Scammer")){
            throw new CreditAccountFrozenException();
    }
        if (salesOrder.getTotalAmount() > 200000)
            throw new CreditLimitExceededException();

    }
    
}
